package com.ysqcould.web.controller.mp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.mp.domain.MpArticle;
import com.ysqcould.mp.service.IMpArticleService;

import static com.ysqcould.common.utils.PageUtils.startPage;

/**
 * 公众号文章管理Controller
 * 
 * @author jcd
 * @date 2022-10-18
 */
@RestController
@RequestMapping("/mp/article")
public class MpArticleController extends BaseController
{
    @Autowired
    private IMpArticleService mpArticleService;

    /**
     * 查询公众号文章管理列表
     */
    @PreAuthorize("@ss.hasPermi('mp:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(MpArticle mpArticle)
    {
        startPage();
        List<MpArticle> list = mpArticleService.selectMpArticleList(mpArticle);
        return getDataTable(list);
    }

    /**
     * 导出公众号文章管理列表
     */
    @PreAuthorize("@ss.hasPermi('mp:article:export')")
    @Log(title = "公众号文章管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MpArticle mpArticle)
    {
        List<MpArticle> list = mpArticleService.selectMpArticleList(mpArticle);
        ExcelUtil<MpArticle> util = new ExcelUtil<MpArticle>(MpArticle.class);
        util.exportExcel(response, list, "公众号文章管理数据");
    }

    /**
     * 获取公众号文章管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mp:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mpArticleService.selectMpArticleById(id));
    }

    /**
     * 新增公众号文章管理
     */
    @PreAuthorize("@ss.hasPermi('mp:article:add')")
    @Log(title = "公众号文章管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpArticle mpArticle)
    {
        return toAjax(mpArticleService.insertMpArticle(mpArticle));
    }

    /**
     * 修改公众号文章管理
     */
    @PreAuthorize("@ss.hasPermi('mp:article:edit')")
    @Log(title = "公众号文章管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpArticle mpArticle)
    {
        return toAjax(mpArticleService.updateMpArticle(mpArticle));
    }

    /**
     * 删除公众号文章管理
     */
    @PreAuthorize("@ss.hasPermi('mp:article:remove')")
    @Log(title = "公众号文章管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mpArticleService.deleteMpArticleByIds(ids));
    }
}
